package src;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.InputStream;

public class Matser {
    int i=1;
    int j=1;
    int k=1;
    boolean toright=false;
    public Matser(int manx, int many, String imagePath) {
        this.manx = manx;
        this.many = many;
        this.ImagePath = imagePath;
    }
    public Matser(){
    }

    private int manx=700;
    private int many=200;
    private String ImagePath="master/toright1.png";
    private String pose="static";

    public String getPose() {
        return pose;
    }

    public void setPose(String pose) {
        this.pose = pose;
    }

    public int getManx() {
        return manx;
    }

    public void setManx(int manx) {
        this.manx = manx;
    }

    public int getMany() {
        return many;
    }

    public void setMany(int many) {
        this.many = many;
    }

    public String getImagePath() {
        return ImagePath;
    }

    public void setImagePath(String imagePath) {
        ImagePath = imagePath;
    }
    public BufferedImage StreamToImage(String str){
        InputStream resourceAsStream = this.getClass().getClassLoader().getResourceAsStream(str);
        BufferedImage bufferedImage=null;
        try {
            bufferedImage= ImageIO.read(resourceAsStream);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return bufferedImage;

    }

    public void drawMe(Graphics g){




        if(pose.equals("right")) {



            ImagePath = "master/toright" + i + ".png";
            BufferedImage bufferedImage = StreamToImage(ImagePath);
            i++;

            manx += 6;

            Image image = new ImageIcon(bufferedImage).getImage();
            g.drawImage(image, manx, many, null);
            if (i > 5) {
                toright=true;

                i = 1;
                this.pose="static";
            }

        }
        else if(pose.equals("left")) {


            ImagePath = "master/toright" + i + "-modified.png";
            BufferedImage bufferedImage = StreamToImage(ImagePath);
            i++;
            manx -= 10;

            Image image = new ImageIcon(bufferedImage).getImage();
            g.drawImage(image, manx, many, null);
            if (i > 5) {
                toright=false;
                i = 1;
                this.pose="static";
            }

        }
        else if(pose.equals("foot"))
        {
           if(toright) {

               ImagePath = "master/foot" + j + ".png";
               BufferedImage bufferedImage = StreamToImage(ImagePath);
               j++;
               manx += 3;

               Image image = new ImageIcon(bufferedImage).getImage();
               g.drawImage(image, manx, many, null);
               if (j > 6) {
                   j = 1;
                   this.pose = "static";
               }
           }
           else
               {


               ImagePath = "master/foot" + j + "-modified.png";
                   BufferedImage bufferedImage = StreamToImage(ImagePath);
               j++;
               manx -= 3;

               Image image = new ImageIcon(bufferedImage).getImage();
               g.drawImage(image, manx, many, null);
               if (j > 6) {

                   j = 1;
                   this.pose = "static";
               }

           }

        }
        else if(pose.equals("hand")) {
            if(toright) {

                ImagePath = "master/hand" + k + ".png";
                BufferedImage bufferedImage = StreamToImage(ImagePath);
                k++;
                manx += 1;

                Image image = new ImageIcon(bufferedImage).getImage();
                g.drawImage(image, manx, many, null);
                if (k > 6) {

                    k = 1;
                    this.pose = "static";
                }
            }
            else
            {
                ImagePath = "master/hand" + k + "-modified.png";
                BufferedImage bufferedImage = StreamToImage(ImagePath);
                k++;
                manx -= 1;

                Image image = new ImageIcon(bufferedImage).getImage();
                g.drawImage(image, manx, many, null);
                if (k > 6) {

                    k = 1;
                    this.pose = "static";
                }

            }

        }
        else if(pose.equals("defense")) {

            if(toright){
                ImagePath = "master/Defense.png";
                BufferedImage bufferedImage = StreamToImage(ImagePath);
                Image image = new ImageIcon(bufferedImage).getImage();
                g.drawImage(image, manx, many, null);

            }
            else
            {
                ImagePath = "master/Defense-modified.png";
                BufferedImage bufferedImage = StreamToImage(ImagePath);
                Image image = new ImageIcon(bufferedImage).getImage();
                g.drawImage(image, manx, many, null);

            }




        }
//        else if(pose.equals("lefthand")){
//            ImagePath = "master/foot" + i + "-modified.png";
//            i++;
//            manx += 10;
//
//            Image image = new ImageIcon(ImagePath).getImage();
//            g.drawImage(image, manx, many, null);
//            if (i > 6) {
//                toright=true;
//                i = 1;
//                this.pose="static";
//            }
//
//
//        }
//        else if(pose.equals("leftfoot")){
//            ImagePath = "master/foot" + i + "-modified.png";
//            i++;
//            manx += 10;
//
//            Image image = new ImageIcon(ImagePath).getImage();
//            g.drawImage(image, manx, many, null);
//            if (i > 6) {
//                toright=true;
//                i = 1;
//                this.pose="static";
//            }
//
//        }

        else{
            if(toright)
            {
                ImagePath = "master/toright" + 1 + ".png";
                BufferedImage bufferedImage = StreamToImage(ImagePath);
                Image image = new ImageIcon(bufferedImage).getImage();
                g.drawImage(image, manx, many, null);

            }
            else
            {
                ImagePath = "master/toright" + 1 + "-modified.png";
                BufferedImage bufferedImage = StreamToImage(ImagePath);
                Image image = new ImageIcon(bufferedImage).getImage();
                g.drawImage(image, manx, many, null);
            }


        }








    }
}
